package com.sky.mapper;/**
 * @ProjectName: sky-take-out
 * @Package: com.sky.mapper
 * @ClassName: OrderMapper
 * @Author: 王加其
 * @Date: 2023/4/25 11:28
 * @Version: 1.0
 */

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 *@author:王加其
 *@date:2023/4/25 11:28
 *@modified By:
 **/
@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<OrderVO> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    OrderVO getVoById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 根据状态和时间查询
     * @param pendingPayment
     * @param localDateTime
     * @return
     */
    @Select("select * from orders where status = #{pendingPayment} and order_time < #{localDateTime}")
    List<Orders> queryByStatusAndOrderTime(Integer pendingPayment, LocalDateTime localDateTime);

    /**
     * 批量修改
     * @param ids
     * @param build
     */
    void batchUpdate(@Param("ids") List<Long> ids, @Param("o") Orders build);

    List<Map> statistics();

    Double sumAmountByParams(Map paramMap);

    List<Map> groupSumAmountByParams(Map paramMap);

    List<Map> groupCountOrderByParams(Map paramMap);

    List<GoodsSalesDTO> groupSumNumberByParams(Map params);

    /**
     * 根据动态条件统计营业额数据
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
